package com.helwen.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/***
*
*
 * @param
*@author:Dell
*@date:2021/7/1 10:57
*@return:
 * @return 测试用java打开本地exe程序
*
 * @author: heqiwen
 * @date : 2021/7/1 10:57
 */
public class OpenExe {

    public static void main(String[] args) {
        //exe文件路径
        //cuteCmd("C:\\Program Files (x86)\\NetSarang\\Xshell 7\\Xshell.exe");//xshell启动
        cuteCmd("C:\\Program Files (x86)\\Oray\\SunLogin\\SunloginClient\\SunloginClient.exe");//向日葵
    }

    public static String cuteCmd(String command){
        Runtime runtime = Runtime.getRuntime();
        StringBuilder builder = null;
        try {
            //如果路径中有空格： java中需额外加一对双引号，以及再加一个空格（因为路径有空格，故路径还需用双引号包一次）
            Process process = runtime.exec("cmd /c start \"\" \"" + command+"\"");
            BufferedReader brBufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
            String line = "";
            builder = new StringBuilder();
            while ((line = brBufferedReader.readLine()) != null) {
                System.out.println(line);
                builder.append(line);
            }
            process.waitFor();
            brBufferedReader.close();
            process.destroy();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return builder.toString();
    }


}
